#'
#' generate a new population or community object by torus-translation
#'
#'
#'
#'
#'
#'
#'@examples
#'pop=rpopulation()
#'
#'plot(pop)
#'
#'plot(rtorus(pop))
#'
#'data(BCI)
#'rtorus(BCI)

rtorus=function(obj){
  UseMethod("rtorus")
}

rtorus.population=function(pop){
  plotdim=plotdim(pop)
  pop$x=pop$x+runif(1,0,plotdim[1])
  modx=pop$x>plotdim[1]
  pop$x[modx]=pop$x[modx]-plotdim[1]
  
  pop$y=pop$y+runif(1,0,plotdim[2])
  mody=pop$y>plotdim[2]
  pop$y[mody]=pop$y[mody]-plotdim[2]
  return(pop)
}

rtorus.community=function(com){
  pops=split.community(com)
  pops=lapply(pops,rtorus)
  newcom=lmerge(pops)
  return(newcom)
}